<template>
  <el-dialog :title="dialogProps.title" :visible.sync="dialogProps.visible" width='400px'  append-to-body  :fullscreen = 'Global.currentDevice'>
        <el-form   align='left' :model="form" ref='form'  :rules='rules' :label-position='Global.dialog_label_Position'>
              <el-form-item label="旧密码："  prop='oldpassword' >
                    <el-input v-model.trim="form.oldpassword"  type='password'  :show-password='true' placeholder='请输入旧密码'></el-input>
              </el-form-item>
              <el-form-item label="新密码："  prop='newpassword' >
                    <el-input v-model.trim="form.newpassword"  type='password'  :show-password='true' placeholder='请输入新密码'></el-input>
              </el-form-item>
        </el-form>
        
        <div slot="footer" class="dialog-footer">
              <el-button   @click="close() ">取 消</el-button>
              <el-button type="primary" @click="submit('form')">确 定</el-button>
        </div>
  </el-dialog>
</template>

<script charset="utf-8" type="text/javascript">
import { Modify_pass }  from '@/api/homework/index'
export default {
  name: 'ModifyPass',
  data() {
    return {

      //dialogo基本信息  显示隐藏状态  title 
      dialogProps: {
        visible: false,
        action: '',
        title: '修改个人密码'
      },
      form:{
          oldpassword:'',
          newpassword:'',
      },
      rules:{
          oldpassword:[
            { required:true,message:'请输入密码'}
          ],
          newpassword:[
            { required:true,message:'请输入密码'}
          ]
          
      },

    }
  },
  created(){

  },
  methods: {
      pageInit(){
        
      },
      /*提交*/
      submit(formName){

          this.$refs[formName].validate(valid => {
              //通过验证后
              if (valid) {
                  
                  Modify_pass(this.form.oldpassword,this.form.newpassword).then(res=>{
                        if(res.data.flag == true){
                            this.$message({type:'success',message:res.data.msg})
                            this.dialogProps.visible = false
                         
                        }
                       
                  }).catch(error=>{
                    console.log(error)
                  })

              } 
          })
      },
      close(){
          this.dialogProps.visible=false
          this.$refs.form.clearValidate()
      },
     
  },
  mounted: function() {
    this.$nextTick(() => {
      this.$on('openDialog', function() {
        
            this.pageInit()
            this.dialogProps.visible = true
            this.form.oldpassword = ''
            this.form.newpassword = ''

            this.$nextTick(() => {
                this.$refs.form.clearValidate()
            })
      })
      
    })
  },
  updated(){
    
  },
  components:{
    
  }
}
</script>

<style  scoped>
</style>


